package com.gemptc.service.iphone;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.gemptc.bean.UserBean;
import com.gemptc.daoimp.LoginImp;



/**
 * Servlet implementation class Login
 */
@WebServlet("/Login")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Login() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter printWriter=response.getWriter();
		String user_name = request.getParameter("user_name");
		String user_password = request.getParameter("user_password");
		// 登录
		LoginImp loginDaoImp=new LoginImp();
		String flag1 = loginDaoImp.logincheck(user_name, user_password);
		System.out.println(flag1);
		if (!flag1.equals("0")) {
			printWriter.write(flag1);		
		} else {
			printWriter.write("0");	
		}
		/*PrintWriter printWriter=response.getWriter();
		String user_name = request.getParameter("user_name");
		String user_password = request.getParameter("user_password");
		// 登录
		LoginImp loginDaoImp=new LoginImp();
		UserBean userbean = loginDaoImp.logincheck(user_name, user_password);
		JSONArray jsonArray = JSONArray.fromObject(userbean);
		printWriter.write(jsonArray.toString());
		printWriter.close();*/
	}

}
